package cn.tedu.dao;

import java.sql.*;

public class Test1 {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取和数据库的连接
        String url="jdbc:mysql://localhost:3307/cgb2104?characterEncoding=utf8";
        String user="root";
        String pwd="root";
        Connection con= DriverManager.getConnection(url,user,pwd);
        //3.获取传输器
        Statement st=con.createStatement();

        //4.执行sql语句
        ResultSet re=st.executeQuery("select  * from students");
        //int rows=st.executeUpdate("insert into students values (110,'张三','男','2001-02-20','96325')");
       // System.out.println(rows);
        //5.解析结果集
        while (re.next()){//判断结果集里是否有数据
            for (int i = 1; i <=5 ; i++) {

                System.out.println(re.getString(i));
            }

        }

        //6.关闭资源
        //re.close();
        st.close();
        con.close();

    }
}